import { Component, OnInit } from "@angular/core";
import { ChangeForm } from "./change-pass.class";
import { ChangePassService } from "./change-pass.service";

@Component({
  selector: 'change-pass',
  templateUrl: 'change-pass.component.html',
  styleUrls: ['change-pass.scss'],
  providers: [ChangePassService]
})
export class ChangePassComponent implements OnInit {
  private changeUrl: string = '/platform/user/passChange';
  private changeForm: ChangeForm;
  private msg: string;
  private errorMsg: string;

  constructor(private _service: ChangePassService) {
  }

  ngOnInit() {
    this.changeForm = new ChangeForm();
  }

  onSubmit() {
    this._service.submit(this.changeUrl, this.changeForm).then(res => {
        if (res.status === 'success') {
          this.msg = '密码修改成功';
        } else {
          this.errorMsg = res.data ? res.data : "网络可能发生错误 稍后再试";
        }
      },
      error => {
        this.errorMsg = error;
      }
    );
  }
}
